
/**
 * 界面动画组件
 * @class ViewAnimation
 * @summary 继承cc.Component, 只需要prefabs中挂载
 * 
 */

cc.Class({
    extends: cc.Component,

    properties: {
        target: {
            default: null,
            type: cc.Node
        },

        type : 1,

        openData : {
            default: [],
            type: cc.Float
        },

        closeData : {
            default: [],
            type: cc.Float
        }
    },

    onDestroy()
    {
        if (this.mOpenCallback)
        {
            this.mOpenCallback = null
        }
    },

    start()
    {
        if (this.type > 0)
        {
            let ViewPreAnimations = require('ViewPreAnimations')

            let d = ViewPreAnimations.open[this.type]
            if (d)
            {
                d(this.target || this.node, this.openData, this.openCallback)

                return
            }
        }   

        this.openCallback && this.openCallback()
    },

    close(callback)
    {
        if (this.type > 0)
        {
            let ViewPreAnimations = require('ViewPreAnimations')

            let d = ViewPreAnimations.close[this.type]
            if (d)
            {
                d(this.target || this.node, this.closeData, callback)

                return
            }
        }   

        callback && callback()
    },

    setOpenCallback(callback)
    {
        this.openCallback = callback
    }
})
